VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "TestSetupErrorHandler"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private mLogger As Logger

Private mHandler As SetupErrorHandler
Private mRaise As Boolean
Private mRaiseInError As Boolean

Public Sub testCallWithNoError()
givenHandler
whenCalledWithNoError
thenNoErrorReported
thenErrObjectIsClear
End Sub
Public Sub testCallWithError()
givenHandler
whenCalledWithError
thenErrorReported
thenErrObjectIsClear
End Sub


''
''
Private Sub givenHandler()
Set mHandler = New SetupErrorHandler
mHandler.init Me, Me, Me
End Sub

Private Sub whenCalledWithNoError()
On Error GoTo whenCalledWithNoError_Error

mHandler.forward

Exit Sub

whenCalledWithNoError_Error:
mLogger.Log "whenCalledWithNoError"
mLogger.Log Err.number
End Sub
Private Sub whenCalledWithError()
mRaise = True
whenCalledWithNoError
End Sub

Private Sub thenNoErrorReported()
assert.equals mLogger.Count, 3
assert.equals mLogger.First, "forward", "forward called first"
assert.equals mLogger.Second, "noError", "noError"
assert.equals mLogger.Third, 0, "Error number is 0"
End Sub
Private Sub thenErrorReported()
assert.equals mLogger.Count, 5
assert.equals mLogger.First, "forward", "forward called first"
assert.equals mLogger.Second, "handleError", "handleError"
assert.equals mLogger.Third, 1001, "Error number"
assert.equals mLogger.Fourth, "whenCalledWithNoError", "Error string"
assert.equals mLogger.Fifth, 1002, "Error number"
End Sub
Private Sub thenErrObjectIsClear()
assert.equals Err.number, 0, "Number is 0"
End Sub


'
'Methods for a Caller to call
'
Public Sub forward()
mLogger.Log "forward"
RaiseError
End Sub
Private Sub RaiseError()
If mRaise Then
    Err.Raise 1001
End If
End Sub
Public Sub noError()
mLogger.Log "noError"
mLogger.Log Err.number
End Sub
Public Sub handleError()
mLogger.Log "handleError"
mLogger.Log Err.number
End Sub


'OPTIONAL METHODS
Public Sub setup()
Set mLogger = New Logger
mRaise = False
mRaiseInError = False
End Sub

Public Function NumOfAsserts() As Long
NumOfAsserts = 12
End Function


